<?php
//vim:set expandtab tabstop=3 shiftwidth=3 softtabstop=3 foldcolumn=1 foldmethod=marker:
/**
 * 项目名:  LTE MIS
 * 文件名:  index.php
 * 
 * 系统的主要入口
 *
 * index.php是系统的主要调用接口，它的主要工作是接受用户的输入请求
 * 并读入配置文件，并把从配置文件里寻找对应的类，然后将用户的请求转发给
 * 相应的类，由相应的类调用相应的业务逻辑处理类，得到业务的数据返回后，
 * 再根据配置返回相应的视图类，并使用视图类显示结果给用户。
 *
 * PHP Version 5
 *
 * @package:   NULL
 * @author:    Mike.G   中文名; 黄叶<hylinux@gmail.com>
 *  @license:   http://www.gnu.org/copyleft/lesser.html  LGPL License 2.1 
 *  @copyright: http://www.5anet.com
 */

//设置Session的过期时间，并启动Session
session_set_cookie_params(3000);
session_start();

//包含配置文件，如果不存在，则报错
if ( file_exists( './config/config.inc.php' ) ) {
   include_once './config/config.inc.php';
} else {
   die("Can't open the configure file.\n");
}



//定义访问的根URL
define('ROOT_URL',  $global_config_root_url); //你的URL存取位置，注意最后的 "/"


//定义安装路径
define('ROOT_PATH',  $global_config_root_path); //你的安装路径, 注意最后的 "/"

//定义配置的绝对路径
define('CONFIG_PATH', ROOT_PATH.'config/');

//定义库的路径
define('LIB_PATH', ROOT_PATH.'lib/');

//定义函数的路径
define('FUNCTION_PATH', ROOT_PATH.'function/');

//定义类的路径
define('CLASS_PATH', ROOT_PATH.'class/');

//定义语言包的路径
define('LANG_PATH', ROOT_PATH.'lang/');

//定义主题的路径
define('THEME_CONFIG_PATH', ROOT_PATH.'lang/res/');

//定义编译后的主题路径
define('DATA_CACHE_PATH', $global_config_cache_path);

//定义主题左包括界符
define('THEME_LEFT_DELIMITER',  $global_config_smarty_left_delimiter);

define('THEME_RIGHT_DELIMITER', $global_config_smarty_right_delimiter);

//定义放置系列化后的对象路径
define('OBJECT_CACHE_PATH',  DATA_CACHE_PATH.'object/');




//数据库缓冲存储路径
$ADODB_CACHE_DIR = DATA_CACHE_PATH.'adodb/';


//由于使用Smarty模板系统，
//因此我们必须关闭这个选项
if ( !get_magic_quotes_gpc() ) {
   ini_set('magic_quotes_gpc', 1);
}

if ( get_magic_quotes_runtime() ) {
      set_magic_quotes_runtime(0);
}




//如果用户已经登录，则可以设定用户的一些参数。例如用户的语言
//用户喜欢的桌面，
$user_lang = '';
$user_theme = '';
if ( isset($_SESSION['user']) ) {
   $user_lang = $_SESSION['user']['lang'];
   $user_theme = $_SESSION['user']['theme'];
   $user_time  = $_SESSION['user']['localtime'];
} else {
   if ( $_COOKIE['user'] ) {
      //确认Session里复制一份
      //      $_SESSION['user'] = unserialize(stripslashes($_COOKIE['user']));
      
      $temp_user_info = unserialize(stripslashes($_COOKIE['user']));

      include_once CLASS_PATH.'main/DB.class.php';
      $dbh = DB::getConnection();
      //验证一下这个cookie是否是真实的。
      $temp_user_name = $temp_user_info['name'];
      $temp_user_check = $temp_user_info['check'];

      $sql = 'select count(*) as num from base_user_info where lower(user_name)=? and user_password=? '.
         ' and status=0 ';
      $sth = $dbh->Prepare($sql);
      $res = $dbh->Execute($sth, array(strtolower($temp_user_name), $temp_user_check));
      $rows = $res->FetchRow();

      if ( $rows['num'] ) {
         $_SESSION['user'] = $temp_user_info;
         $user_lang = $_SESSION['user']['lang'];
         $user_theme = $_SESSION['user']['theme'];
         $user_time  = $_SESSION['user']['localtime'];
      }
   }
}

if ( !$user_lang ) {
   $user_lang = 'zh';
}

if ( !$user_theme ) {
   $user_theme = 'default';
}


//设置默认的时区
date_default_timezone_set($system_default_timezone_set);


// the image access URL
if ( !defined('IMAGE_URL') ) {
   define('IMAGE_URL', ROOT_URL.'theme/'.$user_theme.'/images/');
}

// the theme access URL
if ( !defined('THEME_URL') ) {
   define('THEME_URL', ROOT_URL.'theme/'.$user_theme.'/');
}



// the theme path
if ( !defined('THEME_PATH') ) {
   define('THEME_PATH', ROOT_PATH.'theme/'.$user_theme.'/');
}




// define the system language
if ( !defined('SYSTEM_LANG') ) {
   define('SYSTEM_LANG', $user_lang);
}


// website email
define('WEBSITE_EMAIL', $system_admin_email);

//定义可视化web编辑器的参数
define('FCKEDITOR_BASEPATH', $system_fckeditor_basepath);
define('FCKEDITOR_UPLOADDIR', $system_fckeditor_uploaddir);



# include the application defined file
if ( file_exists(CLASS_PATH.'/main/Application.class.php') ) {
   include_once CLASS_PATH.'/main/Application.class.php';
} else {
   die("Can't include the Application defined file.\n");
}

# defined a Application instance, and run this Application
$app = Application::getInstance();
$app->run();

?>
